package edu.whu.powersoap;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BaiduMapOptions;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.model.LatLng;

/**
 * 演示MapView的基本用法
 */
public class BaseMapDemo extends Activity {
	@SuppressWarnings("unused")
	private static final String LTAG = BaseMapDemo.class.getSimpleName();
	private MapView mMapView;
	private BaiduMap mBaiduMap;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Intent intent = getIntent();
//		if (intent.hasExtra("x") && intent.hasExtra("y")) {
//			// 当用intent参数时，设置中心点为指定点
//			Bundle b = intent.getExtras();
//			LatLng p = new LatLng(b.getDouble("y"), b.getDouble("x"));
//			mMapView = new MapView(this,
//					new BaiduMapOptions().mapStatus(new MapStatus.Builder()
//							.target(p).build()));
//		} else {
//			mMapView = new MapView(this, new BaiduMapOptions());
//		}
		Bundle b = intent.getExtras();
		LatLng p = new LatLng(b.getDouble("y"), b.getDouble("x"));
		mMapView = new MapView(this,
				new BaiduMapOptions().mapStatus(new MapStatus.Builder()
						.target(p).build()));
		setContentView(mMapView);
		mBaiduMap = mMapView.getMap();

		BitmapDescriptor bd = BitmapDescriptorFactory
				.fromResource(R.drawable.icon_gcoding);
		LatLng ll = new LatLng(intent.getExtras().getDouble("y"), intent.getExtras().getDouble("x"));
		OverlayOptions oo = new MarkerOptions().icon(bd).position(ll);
		mBaiduMap.clear();
		mBaiduMap.addOverlay(oo);
		MapStatusUpdate u = MapStatusUpdateFactory
				.newLatLngZoom(ll, 17);
		mBaiduMap.animateMapStatus(u);
		
	}

	@Override
	protected void onPause() {
		super.onPause();
		// activity 暂停时同时暂停地图控件
		mMapView.onPause();
	}

	@Override
	protected void onResume() {
		super.onResume();
		// activity 恢复时同时恢复地图控件
		mMapView.onResume();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		// activity 销毁时同时销毁地图控件
		mMapView.onDestroy();
	}

}
